<template>

<div style="padding-top:13px;">    
<div class="card" style="color: white;height: 163px;">
    <div style="margin: 15px;">
         <span v-if="!isLogin">
         <form action="" name=ThisForm method="post">
							       <table width="100%" align="left" border="0" cellpadding="4" cellspacing="4">
										<tr align='center'  style="height: 38px;">
										    <td width="50" align="right">
										         账号：
										    </td>
										    <td align="left">
										        <input type="text" v-model.trim="user.username" style="width: 153px;"/>
										    </td>
										</tr>
										<tr align='center'  style="height: 38px;">
										    <td width="50" align="right">
										         密码：
										    </td>
										    <td align="left">
										        <input type="password" v-model.trim="user.password" style="width: 153px;" value=""/>
										    </td>
										</tr>
										
										<tr align='center'  style="height: 38px;">
										    <td width="50" align="right">
										        &nbsp;
										    </td>
										    <td align="left">
										       <input type="button" value="提交" style="width: 70px;" @click="userLogin()" />&nbsp; 
										       <input type="button" value="注册" style="width: 70px;" @click="userReg()"/>&nbsp;
										    </td>
										</tr>
								 </table>
		 </form> 
         </span>

        <span v-else>
            <span style="color: white;font-family: Microsoft Yahei;font-size:14px">欢迎您：{{user.username}}</span> &nbsp;&nbsp;&nbsp;&nbsp;
            <a style="color: white;font-family: Microsoft Yahei;" href="javascript:;" @click="userLogout()">安全退出</a> &nbsp;&nbsp;&nbsp;&nbsp;
            <A style="color: white;font-family: Microsoft Yahei;" href="/auser/index.html">管理中心</A>&nbsp;&nbsp;&nbsp;&nbsp;
        </span>
    </div>  
</div>

    
<div class="links whitebg">
      <h2 class="htitle"><span class="sqlink"><!-- <a href="#">1111</a> --></span>友情链接</h2>
      <div>
        <a href="http://www.baidu.com">baidu</a>&nbsp;&nbsp;
        <a href="https://www.china.com/">中华网</a>&nbsp;&nbsp;
      </div>
</div>
</div>    
    
    
    
    


</template>

 
<script>
    module.exports = {
        data: function() {
            return {
                isLogin: false,
                user:{
				  username:"",
                  password:"",
                },
                
            }
        },


        methods: {
            handeler() {
                this.count = this.count + 1;
            },
            userLogout(){
               if(confirm('确实要退出吗?')){
                  localStorage.removeItem("user");
                  window.location.href="/index.html";
               }
               
               
            },
            userLogin()
			{
				if(this.user.username=="")
				{
					alert("请输入账号");
					return;
				}
				if(this.user.password=="")
				{
					alert("请输入密码");
					return;
                }
				
				axios({
						method: 'POST',
						url: '/userLogin',
						params:{
							username:this.user.username,
							password:this.user.password,
						}
						}).then(data => {
							if (data.data.state == 66)
							{
								alert("登录成功");
								var user=data.data.data;
                                localStorage.setItem("user",JSON.stringify(user));//吧user对象转成json格式数据，然后存储到localStorage
                                
                                location.href="/index.html";
							} 
						    if (data.data.state == 45)
							{
								alert("账号错误");
							}
							if (data.data.state == 46)
							{
								alert("密码错误");
							}
						}).catch(error => {
							//console.log(error);
							alert(error);
						})
			},
			

			userReg()
			{
				var url="/view/user/userReg.html";
                window.location.href=url;
			}
  

        },

        created()
		{
			var userJsonString = localStorage.getItem("user");
            if(userJsonString !=null)//判断是否登录
            {
                var user=JSON.parse(userJsonString);
                this.user=user;
                this.isLogin=true;
            }
            else
            {
               
            }

		}

    }


</script>


<style>
   @import url();
</style>	
